package cn.jinjimi.app.presenter;

import cn.jinjimi.app.AccountManager;
import cn.jinjimi.app.controller.event.LoginSuccessEvent;
import cn.jinjimi.app.controller.event.NoticeEvent.NoticeBigDayEvent;
import cn.jinjimi.app.controller.event.NoticeEvent.NoticeEvent;
import cn.jinjimi.app.custom.iview.CustomersView;
import cn.jinjimi.app.custom.ui.fragment.CustomerFragment;
import cn.jinjimi.app.interfaces.IView;
import cn.jinjimi.app.managers.NoticeManager;
import cn.jinjimi.app.store.entity.NoticeEntity;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * 主页-客户 业务控制器
 * Created by jinsen on 15/11/7.
 */
public class CustomersPresenter extends NetBasePresenter {

    CustomersView mView;

    public CustomersPresenter(IView view) {
        super(view);
        mView = (CustomersView) view;
        initData();
    }

    private void initData() {
        // 没有登录或者没有点击过start按钮
        if (!AccountManager.getInstance().isLogin()) {
            mView.showGuideView();
        }
        NoticeManager.getNoticesByCode(NoticeEntity.TypeBigDay);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onLoginSuccessEvent(LoginSuccessEvent event) {
        mView.showPager(CustomerFragment.PAGER_ALL);
        if (AccountManager.getInstance().isLogin()) {
            mView.hideGuideView();
        } else {
            mView.showGuideView();
        }
    }

    /* 收到红点数据 */
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onNoticeBigDayEvent(NoticeBigDayEvent event) {
        if (event.state == NoticeEvent.StateAdd) {
            mView.showRedRemind(event.count);
        }
    }

}